package com.trailwalker.javafx.utils.style;

import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.Region;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;

public class StyleUtils {

    private static final String TAG = StyleUtils.class.getSimpleName();

    /**
     * 获取背景样式
     *
     * @param color   颜色
     * @param radius  四个圆角大小
     * @param padding 内边距
     * @return 返回背景样式
     */
    public static Background getBackground(String color, int radius, int padding) {
        Insets insets = new Insets(padding);
        CornerRadii cornerRadii = new CornerRadii(radius);
        return new Background(new BackgroundFill(Paint.valueOf(color), cornerRadii, insets));
    }

    /**
     * 获取背景样式
     *
     * @param color  颜色
     * @param radius 四个圆角大小
     * @return 返回背景样式
     */
    public static Background getBackGround(String color, int radius) {
        return getBackground(color, radius, 0);
    }

    /**
     * 获取背景样式
     *
     * @param color 颜色
     * @return 返回背景样式
     */
    public static Background getBackGround(String color) {
        return getBackground(color, 0, 0);
    }

    public static void setBackgroundColor(Node node, String color) {
        node.setStyle(node.getStyle() + "-fx-background-color:" + color + ";");
    }

    public static void setBorderColor(Node node, String color) {
        node.setStyle(node.getStyle() + "-fx-border-color:" + color + ";");
    }

    public static void setTextColor(Node node, String color) {
        node.setStyle(node.getStyle() + "-fx-text-fill: " + color + ";");
    }

    public static void setBorderRadius(Region region, double width, double height, double radius) {
        Rectangle rectangle = new Rectangle();
        rectangle.setWidth(width);
        rectangle.setHeight(height);
        rectangle.setArcWidth(radius * 2);
        rectangle.setArcHeight(radius * 2);
        region.setClip(rectangle);
    }
}
